package com.ymttest.common.enums;

/**
 * 
 * @author songyefeng
 * @date 2016-06-23
 */
public enum SalesTypeStringEnum {
	/**
	 * 现货
	 */
	AlreadyInStock(1),

	/**
	 * 直播
	 */
	Live(2);

	private int intValue;
	private static java.util.HashMap<Integer, SalesTypeStringEnum> mappings;

	private synchronized static java.util.HashMap<Integer, SalesTypeStringEnum> getMappings() {
		if (mappings == null) {
			mappings = new java.util.HashMap<Integer, SalesTypeStringEnum>();
		}
		return mappings;
	}

	private SalesTypeStringEnum(int value) {
		intValue = value;
		SalesTypeStringEnum.getMappings().put(value, this);
	}

	public int getValue() {
		return intValue;
	}

	public static SalesTypeStringEnum forValue(int value) {
		return getMappings().get(value);
	}
	
	public static String findByCodeToString(Integer code) {
        SalesTypeStringEnum e = findByCode(code);
        return e == null ? null : e.toString();
    }
	
	public static SalesTypeStringEnum findByCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (SalesTypeStringEnum type : SalesTypeStringEnum.values()) {
            if (type.getValue() == code) {
                return type;
            }
        }
        return null;
    }
	
	public static void main(String[] args) {
		SalesTypeStringEnum s = SalesTypeStringEnum.forValue(1);
		System.out.println(s.toString());
	}
}
